<template>
    <div>
      <el-form  :model="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-row>
          <el-col :span="8" :offset="1">
            <el-form-item label="商品名称" prop="store_name">
              <el-input v-model="ruleForm.store_name" class="custom-input"></el-input>
            </el-form-item>
            <el-form-item label="电话" prop="store_number">
              <el-input v-model="ruleForm.store_number" class="custom-input"></el-input>
            </el-form-item>
            <el-form-item label="商品描述" prop="store_text" style="height: 60px;width: 300px;">
              <el-input type="textarea" v-model="ruleForm.store_text" class="custom-textarea" style="height: 100px;"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="submitForm('ruleForm')">立即保存</el-button>
        <el-button @click="$emit('change', false)">取 消</el-button>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        ruleForm:JSON.parse(sessionStorage.getItem("EditData"))
      };
    },
    props: {
      editData: Object
    },
    model: {
      prop: "dialogFormVisible",
      event: "change"
    },
    methods: {
      submitForm() {
        this.axios({
          method: "PUT",
          url: "stores",
          data: this.ruleForm
        })
        .then(res => {
            console.log('res: ', res);
            if (res.data.code > 0) {
              this.$message({
                message: res.data.msg,
                type: "success"
              });
              // 刷新主页面数据
              this.$emit("refresh");
              // 关闭弹窗
              this.$emit("change", false);
            } else {
              this.$message({
                message: res.data.msg,
                type: "error"
              });
            }
          });
      }
    },
    created() {
      this.ruleForm = JSON.parse(JSON.stringify(this.editData));
    },watch:{
      editData:{
handler(newVal){
  if(newVal){
    this.ruleForm=JSON.parse(JSON.stringify(newVal))
  }
}
      }
    }
  };
  </script>
  
<style scoped>
.demo-ruleForm {
  padding: 20px;
  border: 1px solid #e4e7ed;
  border-radius: 5px;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.store-form {
    border: 1px solid #e4e7ed;
    border-radius: 4px;
    padding: 20px;
    margin-bottom: 20px;
}
.dialog-footer {
    padding: 10px;
    border-top: 1px solid #e4e7ed;
}
  </style>